Main site

Built-in Modules > GeoData Class

GeoData Class

Overview

The GeoData class is designed to retrieve detailed information about a location from a comprehensive database, supporting multiple countries and offering precise geographical data.

Class Definition

class GeoData {
  constructor() {
    // Class constructor
  }

  async getData(value, key, country) {
    // Method to retrieve location data
  }
}

Usage Example

import { GeoData } from "./index.js"
const geodata = new GeoData();
const postal_code = "3029";
const key = "POSTAL_CODE";
const country = "AU";
const cities = await geodata.getData(postal_code, key, country);

In this example, geodata.getData is used to retrieve information for the Australian postal code 3029, utilizing the key "postal_code" to specify the database column for search criteria.

Sample Output

[
  {
    "POSTAL_CODE": 3029,
    "CITY": "TRUGANINA",
    "PROVINCE_ABBR": "VIC",
    "LATITUDE": -37.801,
    "LONGITUDE": 144.7329
  },
  {
    "POSTAL_CODE": 3029,
    "CITY": "TARNEIT",
    "PROVINCE_ABBR": "VIC",
    "LATITUDE": -37.8444,
    "LONGITUDE": 144.6725
  },
  {
    "POSTAL_CODE": 3029,
    "CITY": "HOPPERS CROSSING",
    "PROVINCE_ABBR": "VIC",
    "LATITUDE": -37.8676,
    "LONGITUDE": 144.6928
  }
]

Supported Countries and Search Keys

  • Countries Supported: United States, Canada, Great Britain, and Australia.
  • Search Keys:
    • United States: ZIP_CODE, CITY, COUNTY, STATE, COUNTY_FIPS, STATE_FIPS, TIME_ZONE, DAY_LIGHT_SAVINGS, LATITUDE, LONGITUDE
    • Canada: POSTAL_CODE, CITY, PROVINCE_ABBR, TIME_ZONE, LATITUDE, LONGITUDE
    • Great Britain: POSTAL_CODE, LOCALITY, COUNTRY, COUNTRY_CODE, COUNTY, DISTRICT, ADMINISTRATIVE_AREA_CODE, LATITUDE, LONGITUDE
    • Australia: POSTAL_CODE, CITY, PROVINCE_ABBR, LATITUDE, LONGITUDE

Notes

  • The GeoData class is imported from the module "index.js".
  • The GeoData class offers a robust tool for accessing location-based data, supporting a range of geographical details including postal codes, cities, provinces, and coordinates.
  • This class is especially useful for applications requiring detailed geographical information, such as location-based services, and regional analysis.

The GeoData class enhances the ability to access and utilize detailed location information from a dedicated database, accommodating a wide range of geographical data needs.